package com.msb.sometest;

/**
 * @Auther： WangLei
 * @Date： 2021/8/22-08-22-23:09
 * @Description: com.msb.sometest
 * @version: 1.0
 */
public class SynchronizedDemo1 {
    static int a = 0;
    public static void main(String[] args) {


        for (int i =0 ; i < 3 ; i ++){
            Thread t = new Thread(() -> {
                new SynchronizedDemo1().demo();
            });
            t.setName("Thread-"+i);
            t.start();
        }
    }

    public  void demo(){
        String ss = "";
        synchronized(SynchronizedDemo1.class)
        {
           for(int i = 0;i < 50 ;i++){
            a += 1;
            System.out.println(Thread.currentThread().getName() +" : " + a);
               try {
                   Thread.sleep(10);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        }
    }
}
